{% extends "site_base.html" %}

{% load i18n %}
{% load threadedcommentstags %}

{% load tribes_tags %}
{% load avatar_tags %}
{% load blog_tags %}
{% load wiki_tags %}
{% load voting_tags %}
{% load extra_voting_tags %}
{% load theme_tags %}
{% load in_filter %}
{% load extra_tagging_tags %}


{% block head_title %}{% blocktrans %}Tags{% endblocktrans %}{% endblock %}

{% block body %}
    <h1>{% trans "All Photos Matching " %}<i>"{{ tag }}"</i></h1>
    
    {% if phototags %}
        <div class="thumb-row clearfix">
        {% for photo in phototags %}
                <div class="gallery-photo-thumb">
                    <a href="/photos/details/{{ photo.id }}/"><img src="{{ photo.get_thumbnail_url }}" alt="{{ photo.title }}"/></a><br />
                    from <a href="{% url profile_detail photo.member.username %}">{{ photo.member.username }}</a><br />
                    {% silk "comment" %} <a href="/photos/details/{{ photo.id }}/">{% get_comment_count for photo as commentcount %} {{ commentcount }} Comments</a>
                    <br />
                    Viewed {{ photo.view_count }} Times
                </div>
        {% endfor %}
        </div>
    {% else %}
        No photos matching tag.
    {% endif %}
    
    {% if bookmarktags %}
        {% scores_for_objects bookmarktags as score_dict %}
        
        <h1>All Bookmarks Matching <i>{{ tag }}</i></h1>
        <table class="bookmarks" width="100%">
            {% for bookmark in bookmarktags %}
                <tr class="{% cycle odd,even %}">
                    <td class="meta">
                        <div class="avatar">{% avatar bookmark.bookmark.adder 40 %}</div>
                        <div class="details"><a href="{% url profile_detail bookmark.bookmark.adder.username %}">{{ bookmark.bookmark.adder }}</a></div>
                        {{ bookmark.bookmark.added|date }}
                    </td>
                    
                    <td>
                        <h2><a href="{{ bookmark.bookmark.url }}">{{ bookmark.bookmark.description }}</a></h2>
                        <div class="url">{% if bookmark.bookmark.get_favicon_url %}<img src="{{ bookmark.bookmark.get_favicon_url }}" width="16" height="16" /> {% endif %}{{ bookmark.bookmark.url }}</div>
                        <div class="body">{{ bookmark.bookmark.note|linebreaks }}</div>
                        <div class="tags">{% show_tag_counts bookmark.bookmark.all_tags_with_counts %}</div>
                    </td>
                </tr>
            {% endfor %}
        </table>
        
    {% else %}
        No bookmarks matching tag.
    {% endif %}
    
    
    <h1>{% trans "All Blog Posts Matching " %}<i>"{{ tag }}"</i></h1>
    
    {% if alltags %}
        <p>{% trans "These are blog posts from everyone:" %}</p>
        {% for blog_post in alltags %}
            {% show_blog_post blog_post %}
        {% endfor %}
    {% else %}
        No blog posts matching tag.
    {% endif %}
    
    <h1>{% blocktrans %}All Tribes Matching <i>{{ tag }}</i>{% endblocktrans %}</h1>
    
    <dl>
        {% for tribe in tribe_tags %}
            {% show_tribe tribe %}
        {% endfor %}
    </dl>
    
    {% comment %}
    <h1>{% blocktrans %}All Tribe Topics Matching <i>{{ tag }}</i>{% endblocktrans %}</h1>
    
    {% for topic in tribe_topic_tags %}
        {% show_tribe_topic topic %}
    {% endfor %}
    {% endcomment %}
    
    <h1>{% blocktrans %}All Wiki Articles Matching <i>{{ tag }}</i>{% endblocktrans %}</h1>
    
    <table class="topics">
        {% for article in wiki_article_tags %}
            {% show_teaser article %}
        {% endfor %}
    </table>


{% endblock %}


{% block extra_body %}
    <script>
        function vote(bookmark_id, direction) {
            $.post(bookmark_id + '/' + direction + 'vote/', function(data) {
                var jsonResult = eval('(' + data + ')');
                var new_score = jsonResult.score.score;
                $('#bookmark_' + bookmark_id + '_score').text(new_score + ' point' + (new_score == 1 ? '': 's'));
            });
            if (direction == 'up') {
                $('#up_' + bookmark_id).replaceWith('<a id="up_' + bookmark_id + '" href="#" onclick="return false;"><img src="{{ STATIC_URL }}up_mod.png"/>');
                $('#down_' + bookmark_id).replaceWith('<a id="down_' + bookmark_id + '" href="#" onclick="vote(' + bookmark_id + ', \'clear\'); return false;"><img src="{{ STATIC_URL }}down_grey.png"/>');
            }
            else if (direction == 'down') {
                $('#up_' + bookmark_id).replaceWith('<a id="up_' + bookmark_id + '" href="#" onclick="vote(' + bookmark_id + ', \'clear\'); return false;"><img src="{{ STATIC_URL }}up_grey.png"/>');
                $('#down_' + bookmark_id).replaceWith('<a id="down_' + bookmark_id + '" href="#" onclick="return false;"><img src="{{ STATIC_URL }}down_mod.png"/>');
            }
            else { // clear
                $('#up_' + bookmark_id).replaceWith('<a id="up_' + bookmark_id + '" href="#" onclick="vote(' + bookmark_id + ', \'up\'); return false;"><img src="{{ STATIC_URL }}up_grey.png"/>');
                $('#down_' + bookmark_id).replaceWith('<a id="down_' + bookmark_id + '" href="#" onclick="vote(' + bookmark_id + ', \'down\'); return false;"><img src="{{ STATIC_URL }}down_grey.png"/>');
            }
        }
    </script>
{% endblock %}
